/*
 * SharpGP2.c
 *
 * Created: 27.08.2011 00:59:32
 *  Author: Tavin
 */ 
#include <stdint.h>
#include <stdbool.h>
#include "sharpGP2.h"
#include "adc.h"

SharpGp2Data_t SharpSensorData;

#include "sharpGp2_hardware.h"	



void SharpGP2_init(void)
{
	uint8_t enumerator;

	for (enumerator=0;enumerator<GP2_SENSORS_CONT;enumerator++)
	{
		SharpGP2_loadDefaultSettings(enumerator);
	}
}

/****************************************************************************************/
/*																						*/
/*	SharpGP2_calculateDistance									Author : OG				*/
/*																						*/
/*	Description : Calculate the Distance with the Sensor config							*/
/*																						*/
/*	Version : 1.0					Date :2012.01.09			Status : working		*/
/*																						*/
/****************************************************************************************/
void SharpGP2_calculateDistance(uint8_t index)
{
	if (index >= GP2_SENSORS_CONT)
		return;
	
	
	int64_t tmpValue;
	int64_t v;
	
	v=SharpGP2_getValue(index);
	
	v<<=8;
	v-=SharpGP2_getOffset(index);
	
	tmpValue=SharpGP2_getGradient(index);
	
	tmpValue/=v;
	
	SharpGP2_setDistance(index,tmpValue);


	return ;

}




